<template>
  <div>
    <el-form ref="dataForm" :model="form" label-width="90px">
      <div class="ledgerTitle">基本信息</div>
      <el-row>
        <el-col :span="7">
          <el-form-item label-width="140px" label="被审计单位:" prop="auditedCompanyName">
            {{ form.auditedCompanyName }}
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label-width="110px" label="被审计个人:" prop="auditedUserNames">
            {{ form.auditedUserNames }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="110px" label="审计类型:" prop="auditType">
            <DictTag :options="dict.type.audit_type" :value="form.auditType"></DictTag>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="100px" label="是否披露:" prop="isPublish">
            <div v-if="Number(form.isPublish) === 0">
              <span>否</span>
            </div>
            <div v-else>
              <span>是</span>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7">
          <el-form-item label-width="140px" label="审计区间:" prop="auditDates">
            <span v-if="form.auditStartDate" style="margin-right: 5px;">{{ form.auditStartDate }} 至</span>
            <span style="margin-left: 5px;">{{ form.auditEndDate }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="5" v-if="form.auditType === 1">
          <el-form-item label-width="110px" label="审计子类型:" prop="auditTypeSub">
            {{form.auditTypeSub}}
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="form.auditType === 1">
          <el-form-item label-width="110px" label="任职区间:" prop="tenureDates">
            <span v-if="form.tenureStartDate" style="margin-right: 5px;">{{ form.tenureStartDate }} 至</span>
            <span style="margin-left: 5px;">{{ form.tenureEndDate }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle">工作方案</div>
<!--      <el-row>-->
<!--        <el-col>-->
<!--          <el-form-item style="margin-left: 15px" label-width="90px" label="被审计对象基本情况">-->
<!--            {{ form.auditSubjectProfile }}-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--      </el-row>-->
      <el-row>
        <el-col>
          <el-form-item label-width="140px" label="审计目的:" prop="auditPurpose">
            <pre class="pre-style">{{ form.auditPurpose }}</pre>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label-width="140px" label="审计范围:" prop="auditScope">
            <pre class="pre-style">{{ form.auditScope }}</pre>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle">审计重点</div>
      <el-row>
        <el-table
          ref="table"
          :data="tableData"
          :model="tableData"
          style="width: 100%"
        >
          <el-table-column label="序号" width="100">
            <template #default="{ row, $index }">
              <span>{{ $index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="标题" width="250">
            <template #default="{ row }">
              {{ row.keynoteTitle }}
            </template>
          </el-table-column>
          <el-table-column label="内容">
            <template #default="{ row }">
              <pre class="pre-style">{{ row.keynoteContent }}</pre>
            </template>
          </el-table-column>
          <el-table-column label="应对措施">
            <template #default="{ row }">
              <pre class="pre-style">{{ row.responseMeasures }}</pre>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <div class="ledgerTitle">工作安排</div>
      <el-row>
        <el-col :span="6">
          <el-form-item label-width="140px" label="审计组组长:" prop="auditLeader">
            {{ form.auditLeader }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="110px" label="协审单位:" prop="assistCompanyName">
            {{ form.assistCompanyName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label-width="110px" label="协审单位组长:" prop="assistLeader">
            {{ form.assistLeader }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label-width="140px" label="被审计单位联络员:" prop="auditedCompanyUserName">
            {{ form.auditedCompanyUserName }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="110px" label="协审单位主审:" prop="assistJudge">
            {{ form.assistJudge }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label-width="110px" label="审计组成员:" prop="assistMembers">
            {{ form.assistMembers }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label-width="140px" label="计划工作时间:" prop="projectDates">
            <span v-if="form.projectStartDate" style="margin-right: 5px;">{{ form.projectStartDate }} 至</span>
            <span style="margin-left: 5px;">{{ form.projectEndDate }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label-width="110px" label="实施工作时间:" prop="workDates">
            <span v-if="form.workStartDate" style="margin-right: 5px;">{{ form.workStartDate }} 至</span>
            <span style="margin-left: 5px;">{{ form.workEndDate }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle">工作实施方案文书</div>
      <div class="inputBox" @click="openWord">
        <div class="inputBox">
        <el-input :readonly="true" v-model="form.projectName"></el-input>
        <ul class="fileBar" v-if="form.wordFile">
          <li @click="openWord('view')"><i class="el-icon-search"></i></li>
          <li @click="downWord"><i class="el-icon-download"></i></li>
        </ul>
      </div>
      </div>
    </el-form>
  </div>
</template>

<script>
import {getApply, getApplyByProjectId} from "@/api/adis/project/projectApply";

export default {
  name: 'ProjectApplyAuditView',
  props: {
    id: {
      type: String,
      default: ''
    },
    params: {
      type: Object,
    },
    isAudit: {
      type: Boolean,
      default: false,
    }
  },
  components: {},
  dictTypes: ['audit_type', 'audit_type_1_sub'],
  data() {
    return {
      tableData : [],
      form: {},
    }
  },
  watch:{
    id: {
      handler(val){
        if(val){
          getApply(val).then((res) => {
            if (res.data.data !== null){
              this.handleApplyResponse(res.data.data);
              this.$emit('data-loaded', true);
            } else {
              this.$emit('data-loaded', false);
            }
          }).catch(() => {
            this.$emit('data-loaded', false);
          });
        }
      },deep: true, immediate: true
    },
    params: {
      handler(val) {
        if (val){
          this.handleApplyResponse(val)
        }
      },deep: true, immediate: true
    },
  },
  methods: {
    handleApplyResponse(val) {
      if (val) {
        this.$set(this, "tableData", val.keynoteList);
      } else {
        this.$set(this, "tableData", [])
      }
      this.$set(this, "form", val)
    },
    downWord() {
      if(!this.form.wordFile) {
        this.$message({
          type: "warning",
          message: "该项尚未上传相关文书!"
        });
        return;
      }
      const a = document.createElement('a');
      let url = this.form.wordFile;
      a.setAttribute('download', '');
      a.setAttribute('href', url);
      a.click();
    },
    openWord() {
      if(!this.form.wordFile) {
        this.$message({
          type: "warning",
          message: "该项尚未上传相关文书!"
        });
        return;
      }
      // this.$router.push({path:'/webOffice', query: {url: this.form.wordFile}})
      const { href } = this.$router.resolve({
        path: '/webOffice',
        query: {
          url: this.form.wordFile,
          type: this.isAudit ? 'edit' : 'view',
        }
      });
      window.open(href, '_blank');
    }
  }
}
</script>

